/*************************************************************************
    > File Name: client.cpp
    > Author: Lancer
    > Mail: 18826075768@163.com
************************************************************************/

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

using namespace std;

int global = 1;

int main(){
    pid_t pid;
    int s = 1;
    int* p;
    p = (int*)malloc(sizeof(int));
    *p = 3;
    pid = fork();
    if(pid < 0){
        printf("fail to fork!\n");
        exit(-1);
    }
    else if(pid == 0){
        global++;
        s++;
        (*p)++;
        printf("In sub_process, global: %d, s: %d, *p: %d\n", global, s, *p);
        exit(0);
    }
    else{
        sleep(5);
        printf("In parent_process, global: %d, s: %d, *p: %d\n", global, s, *p);
    }
    return 0;
}